package com.twu.biblioteca;

import java.io.*;
import java.util.Map;

public class ReserveMenuItem implements MenuItem {
    private InteractiveConsole console;
    private Map<Integer, String> library;

    public ReserveMenuItem(InteractiveConsole console, Map<Integer, String> library) {
        this.console = console;
        this.library = library;
    }

    @Override
    public void start() throws IOException {
        console.println("ID of the book you'd like: ");

        String input = console.readln();
        int bookId = Integer.parseInt(input);

        if (haveBook(bookId)) {
            console.println("Thank You! Enjoy the book.");
        } else {
            console.println("Sorry we don't have that book yet.");
        }
    }

    private boolean haveBook(int id) {
        return library.containsKey(id);
    }

    @Override
    public String toString() {
        return "Reserve a book and learn how to kill all humans.";
    }
}
